package com.br.android.widing.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteQuery;

public class WidingCursor extends SQLiteCursor{

	public static final String QUERY = "SELECT * FROM gasto ORDER BY idgasto DESC";
	public static final String QUERY_SOMA_VALORES = "SELECT SUM(valorgasto) AS soma_valores from gasto";
	public static final String QUERY_SOMA_VALORES_POR_CATEGORIA = "SELECT categoriagasto, SUM(valorgasto) AS valor_por_categoria FROM gasto GROUP BY categoriagasto";

	
	public WidingCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
			String editTable, SQLiteQuery query) {
		super(db, driver, editTable, query);
	}

	public static class Factory implements CursorFactory {
        
        public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
                        String editTable, SQLiteQuery query) {
                return new WidingCursor(db, driver, editTable, query);
        }
	}
	
	public int getIdGasto() {
        return getInt(getColumnIndexOrThrow("idgasto"));
	}
	
	public String getNomeGasto() {
		return getString(getColumnIndexOrThrow("nomegasto"));
	}
	
	public double getValorGasto() {
		return getDouble(getColumnIndexOrThrow("valorgasto"));
	}
	
	public String getCategoriaGasto() {
		return getString(getColumnIndexOrThrow("categoriagasto"));
	}
	
	public String getDataGasto() {
		return getString(getColumnIndexOrThrow("datagasto"));
	}
	
	public double getSomaValores(){
		return getDouble(getColumnIndexOrThrow("soma_valores"));
	}
	
	public double getSomaValoresPorCategoria(){
		return getDouble(getColumnIndexOrThrow("valor_por_categoria"));
	}
	
}
